import axios from 'axios'
//Vue.axios/this.axios/this.$http使用axios，一次封装方便协作,
//不用//Vue.prototype.$axios=axios了
import vueAxios from 'vue-axios'
import {dateUtils} from '@/libs/tools.js'

import config from '@/config'
axios.defaults.timeout=10000
axios.defaults.baseURL = config.baseUrl+'tangyin/main' //配置一个基础路径
axios.defaults.withCredentials=true//跨域时携带cookie使用同一session
axios.defaults.crossDomain=true
axios.defaults.headers['Cache-Control']='no-cache'//请求时头部禁用缓存

//响应response拦截器
axios.interceptors.response.use(res => {
	let lastTime= sessionStorage.getItem("lastTime")
	if(lastTime==null){
		lastTime=dateUtils.getDateTime()
	}
	let now=dateUtils.getDateTime()
	let diff=new Date(now).getTime()-new Date(lastTime).getTime()
	if(diff<30*60*1000){
		sessionStorage.setItem("lastTime",now)
		return res
	}else{
		sessionStorage.clear()
		self.location="/"
	}
}, err => {
    console.log('err', err);
  } 
)
export{vueAxios,axios}